<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file='base/common_header'}
    <style>
        .layui-table td, .layui-table th { min-width: auto; }
    </style>
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form class="layui-form topic-form layui-col-space10">
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>测评id</label>
                        <div class="layui-input-inline">
                            <input type="number" id="topic_id" name="topic_id" value="{$bannerInfo.topic_id}" required="" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label for="desc" class="layui-form-label">
                            <span class="x-red">*</span>广告图</label>
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" id="test1">
                                <i class="layui-icon">&#xe67c;</i>上传图片
                            </button>
                            <div class="banner-show" style="width: 200px;margin-top: 5px"><img src="{$bannerInfo.banner_img}" style="width: auto;max-width: 100%;max-height: 100%"></div>
                            <input type="hidden" name="banner_img" value="{$bannerInfo.banner_img}" class="banner_img">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <input type="hidden" name="id" value="{$bannerInfo.id}">
                        <label for="L_repass" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="add" lay-submit="">更新banner</button></div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['form', 'layer'],
        function() {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            //监听提交
            form.on('submit(add)',
                function(data) {
                    $.post("/admin/banner/deal",$('.topic-form').serialize(),function (res) {
                        if(res.error_code != 0){
                            layer.msg(res.msg,{icon:5});
                        }else{
                            //发异步，把数据提交给php
                            layer.msg("修改成功", {
                                    icon: 6
                                },
                                function() {
                                    window.parent.location.reload();
                                    // 获得frame索引
                                    var index = parent.layer.getFrameIndex(window.name);
                                    //关闭当前frame
                                    parent.layer.close(index);
                                });
                        }
                    },'json')
                    return false;
                });
        })

    /**
     * 测评banner上传
     * */
    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        upload.render({
            elem: '#test1' //绑定元素
            ,url: '/api/fileUpload' //上传接口
            ,size: 512
            ,data:{useOrigin:1}
            ,done: function(res){
                //上传完毕回调
                if(res.code == 1){
                    $('#test1').parents('.layui-input-block').find('.banner-show').find('img').attr('src',res.photo)
                    $('#test1').parents('.layui-input-block').find('.banner_img').val(res.photo)
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg('上传失败')
            }
        });
    });
</script>

</html>